<?php
class AdminSys {
	
	private $db;
	private $t_msg_send_list;
	public function __construct() {
		
		$this->db = new Mysql ();
		$this->t_msg_send_list = $this->db->pre . 'msg_send_list';
	}
	
	public function insertSendList($stype, $content, $result) {
		$inData = array ('uid' => user ( 'uid' ), 'username' => user ( 'username' ), 'stype' => $stype, 'content' => $content, 'result' => $result, 'timeline' => time () );
		$this->db->insert ( $this->t_msg_send_list, $inData );
	}
	
	public function getSendList() {
		$sql = "SELECT * FROM " . $this->t_msg_send_list . " WHERE 1 ";
		//搜索条件过滤
		if (Http::get ( 'uid' )) {
			$sql = $sql . "AND uid = '" . Http::get ( 'uid' ) . "' ";
		}
		if (Http::get ( 'username' )) {
			$sql = $sql . "AND username = '" . Http::get ( 'username' ) . "' ";
		}
		if (Http::get ( 'stype' )) {
			$sql = $sql . "AND stype = '" . Http::get ( 'stype' ) . "' ";
		}
		if (Http::get ( 'uid' )) {
			$sql = $sql . "AND uid = '" . Http::get ( 'uid' ) . "' ";
		}
		if (Http::get ( 'stimeline' )) {
			$sql = $sql . "AND timeline >= '" . strtotime ( Http::get ( 'stimeline' ) ) . "' ";
		}
		if (Http::get ( 'etimeline' )) {
			$sql = $sql . "AND timeline <= '" . strtotime ( Http::get ( 'etimeline' ) . ' 23:59:59' ) . "' ";
		}
		//设置分页信息
		$page = new Page ();
		if (Http::get ( 'orderby' )) {
			$page->orderBy = Http::get ( 'orderby' );
			$page->desc = Http::get ( 'sc' );
		} else {
			$page->orderBy = 'id';
		}
		$page->uriStyle = '?';
		$list = $page->getPage ( $sql, 0 );
		$html = $page->htmlPage ();
		//返回搜索结果和分页信息
		return array ('list' => $list, 'html' => $html, 'total' => $page->allNums, 'eachNums' => $page->eachNums );
	}
	/**
	 * 
	 * 删除公告
	 * @param unknown_type $id
	 */
	public function deleteMsg($id) {
		$sql = "DELETE FROM " . $this->t_msg_send_list . " WHERE id IN ( $id )";
		return $this->db->delete ( $sql );
	
	}
}